home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / SAT Invaders demo ƒ / sPlayer.c < prev    next >
Text File  |  1995-01-15  |  2KB  |  101 lines

  1. //• C translation from Pascal source file: sPlayer.p
  2.  
  3. //• ===============================================.
  4. //• ================= Player sprite unit ================.
  5. //• ===============================================.
  6.  
  7. //• Example file for Ingemars Sprite Animation Toolkit.
  8. //• © Ingemar Ragnemalm 1992.
  9. //• See doc files for legal terms for using this code.
  10.  
  11. //• This file is the first of several sprite units, units that holds the full.
  12. //• description of the objects to be animated.
  13.  
  14. //• sPlayer;
  15.  
  16. //• Sprite unit. A sprite unit should include the following routines:
  17. //• Init-procedure, that Initializes private bitmaps.
  18. //• Setup-procedure, that sets variables other than the standard ones set by MakeSprite.
  19. //• Handle-procedure, to be called once per iteration until the sprite dies.
  20. //• Hittask-procedure (optional), for advanced collission handling.
  21.  
  22. //• This is the sprite unit for the player object, in this case a cannon.
  23.  
  24. //• Prototypes, etc.
  25. #include "SAT.h"
  26. #include "InvadeSAT.h"
  27.  
  28. extern void        InitShot(void);
  29. extern pascal void        SetupShot(SpritePtr sp);
  30. extern pascal void        HandleShot(SpritePtr me);
  31.  
  32. //• SoundConst, sShot;
  33.  
  34.  
  35. enum {
  36.     playerSpeed = 16
  37. };
  38.  
  39. static FacePtr playerFace;
  40.  
  41. void InitPlayer ()
  42. {
  43.     playerFace = SATGetFace (134);
  44. }
  45.  
  46. pascal void SetupPlayer (SpritePtr player)
  47. {
  48.     player->face = playerFace;
  49.     SetRect (&player->hotRect, 1, 7, 31, 32);
  50.     player->task = &HandlePlayer;
  51. }
  52.  
  53. pascal void HandlePlayer (SpritePtr me)
  54. {
  55.     Point pt;
  56.     SpritePtr shot;
  57.  
  58.     if (me->kind != 2)
  59.     {
  60.         SATSoundPlay (kraschH, 10, true);
  61.         stillRunning = false;     //• Tell MoveIt that the game is over, to quit the game loop.
  62.         //• Real games make an explosion first.
  63.     }
  64.  
  65.     SetPort (gSAT.wind.port);
  66.     GetMouse (&pt);
  67.  
  68.     me->speed.h = pt.h - me->position.h;
  69.  
  70.     if (me->speed.h < -playerSpeed)
  71.         me->position.h = me->position.h - playerSpeed;
  72.     else if (me->speed.h > playerSpeed)
  73.         me->position.h = me->position.h + playerSpeed;
  74.     else
  75.         me->position.h = me->position.h + me->speed.h;
  76.  
  77.     if (me->position.h > gSAT.offSizeH - 32)     //• xsize.
  78.     {
  79.         me->position.h = gSAT.offSizeH - 32;     //• ev. xsize - 10?.
  80.     }
  81.     if (me->position.h < 0)
  82.     {
  83.         me->position.h = 0;
  84.     }
  85.  
  86.     //• Create shots.
  87.     if (me->mode > 0)
  88.         me->mode--;
  89.     if (me->mode == 0)
  90.         if (Button ())
  91.         {
  92.             shot = SATNewSprite (1, me->position.h + 12, me->position.v, &SetupShot);
  93.             me->mode = 10;
  94.             SATSoundPlay (toffH, 1, false);
  95.         }
  96. }
  97.  
  98.  
  99.  
  100.  
  101.